import com.spring.annotation.*;
import com.spring.aop.MathMethod;
import com.spring.beans.LifeCycle;
import com.spring.beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

/**
 * @Author: shubin_yao
 * @Date: 2021/09/24/13:32
 * @Description:
 */
public class MainTest {
    public static void main(String[] args) {
       /* xml格式*/
       /* ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-contxt.xml");
        User user = (User) applicationContext.getBean("user");
        BeanFactory beanFactory = applicationContext.getParentBeanFactory();
        System.out.println(user);*/

        /*注解格式*/
       /* AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        User user = applicationContext.getBean(User.class);
        System.out.println(user);*/

        /*测试扫描包*/
       /* AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        String[] names = applicationContext.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }*/

        /*测试Scop*/
    /*    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ScopConfig.class);
        User user1 = (User) applicationContext.getBean("user");
        User user2 = (User) applicationContext.getBean("user");

        System.out.println(user1==user2);*/

        /*测试Lazy*/
      /*  AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(LazyConfig.class);
        System.out.println("容器启动。。。。。");
        Object user =  applicationContext.getBean("user");*/

        /* 测试Condition*/
       /* AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConditionConfig.class);
        String[] beanNamesForType = applicationContext.getBeanNamesForType(User.class);
        for (String name : beanNamesForType) {
            System.out.println(name);
        }*/

        /*测试Import*/
        /*AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ImportConfig.class);
        String[] definitionNames = applicationContext.getBeanDefinitionNames();
        for (String name : definitionNames) {
            System.out.println(name);  //含有 com.spring.beans.Work
        }*/

        /*测试FactoryBean*/
       /* AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        Object bean = applicationContext.getBean("factoryBean");  //class com.spring.beans.Work
        Object bean1 = applicationContext.getBean("&factoryBean");  //class com.spring.beans.MyFactoryBean
        System.out.println(bean1.getClass());*/


        /*测试BeanLifeCycle*/
        //容器启动
      /*  AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanLifeCycleConfig.class);
        System.out.println("容器创建完成。。。。");
        applicationContext.getBean("lifeCycle");  //多例时候获取对象才能进行实例化和初始化
        //容器关闭
        applicationContext.close();*/

        /**
         * 测试AOP
         */
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AspeConfig.class);
        MathMethod mathMethod = applicationContext.getBean(MathMethod.class);
        int sum = mathMethod.add(3, 5);
    }
}
